const util = require('../../utils/util.js');
const user = require('../../services/user.js');
const Toast = require('../../utils/toast.js');
Page({
  data: {
    schoollist: [],
    myfollowschool: [],
    followschoollist: [],
    isFromSearch: true, // 用于判断schoollist数组是不是空数组，默认true，空的数组
    currentTab: 1, // 设置加载的第几次，默认是第一次
    isHideLoadMore: true, //"上拉加载"的变量，默认true，隐藏
    isHideLoadComplete: false //“没有数据”的变量，默认false，隐藏
  },
  onLoad: function () {
    this.getschoollist();
    wx.showShareMenu({
      withShareTicket: true
    })
    //this.schoollist()
  },
  getschoollist: function () {
    let that = this;
    util.request('school/getschoollist').then(function (res) {
      console.log(res.data);
      if (res.errno === 0) {
        that.setData({
          schoollist: res.data.schoollist,
        });
      }
    });
  },
  getmyfollowschool:function(){
    let that = this;
    that.setData({
      currentTab: 2,
    });
    util.request('school/getmyfollowschool').then(function (res) {
      console.log(res.data);
      if (res.errno === 0) {
        that.setData({
          followschoollist: res.data.followschoollist,
        });
      }
    });
  },
  followschool: function () {
    let that = this;
    user.checkLogin().then((res) => {
      //console.log(res)
      if (res == true) {
        console.log('已授权')
        that.getmyfollowschool();
      }
    }).catch((err) => {
      console.log('未授权')
    });
  },
  allschool:function(){
    this.setData({
      currentTab:1,
    });
  },
  goSchooldetails: function (e) {
    //console.log(e.currentTarget.dataset.id);
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/schooldetails/schooldetails?id=${id}`
    })
  },
  onShareAppMessage: function (res) {
    return {
      title: '学院分院列表',
      path: 'pages/school/school',
      imageUrl: 'http://p8pho5rm4.bkt.clouddn.com/5bi4.png' || 'http://p8pho5rm4.bkt.clouddn.com/sharelogo_new.png'
    }
  }
})